# 键盘
from selenium.webdriver.common.keys import Keys
# 鼠标
from selenium.webdriver.common.action_chains import ActionChains
# 显示等待
from selenium.webdriver.support.ui import WebDriverWait

class Base():
    def __init__(self,driver):
        self.driver=driver
    def open_url(self,url):
        self.driver.get(url)
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver:driver.find_element(*loc).is_displayed)
            return self.driver.find_element(*loc)
        except Exception as e:
            print(e)
    # 文本封装
    def text(self,loc):
        return self.find_element(loc).text
    # 单击
    def click(self,loc):
        self.find_element(loc).click()
    # 双击
    def double_click(self,loc):
        ActionChains(self.driver).double_click(self.find_element(loc)).perform()
    # 悬浮
    def xuanfu(self,loc):
        ActionChains(self.driver).move_to_element(self.find_element(loc)).perform()
    # 键盘回车
    def enter(self,loc):
        self.find_element(loc).send_keys(Keys.ENTER)
    # 输入
    def send_keys(self,loc,text):
        self.find_element(loc).send_keys(text)
    #切换页面
    def switch(self):
        self.driver.switch_to.window(self.driver.window_handles[-1])
    # 滑动
    def huadong(self):
        self.driver.execute_script('window.scrollTo(0,600)')
    #进入框架
    def frame(self,loc):
        self.driver.switch_to.frame(self.driver.find_element(loc))





